package com.njzxw.fs.commonutil.repository;

import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Mapper
public interface ResouceReq {

    /**
     * 获取资源文件访问路径
     * @param id
     * @return
     */
    @Select("select CONCAT(a.img_host,a.file_name) path from t_resouce_file a where a.id = #{file_id}")
    String getPath(@Param("file_id") String id);

    @Select("select a.AUTO_INCREMENT from information_schema.`TABLES` a where a.TABLE_NAME = #{tableName} and a.TABLE_SCHEMA = DATABASE() ")
    Integer getAutoNum(@Param("tableName") String tableName);

    @Update("ALTER TABLE `${tableName}` AUTO_INCREMENT=${num}")
    Integer updateTableAUtoNum(@Param("tableName") String tableName, @Param("num") int num);

    @Insert("${tableNamesql}")
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    Integer createTmpTable(@Param("tableNamesql") String tableNamesql);

    @Insert("${insertSql}")
    Integer insertInto(@Param("insertSql") String insertSql);

    @Update("${verifySql}")
    Integer verify(@Param("verifySql") String verifySql);

    @Select("select count(1) from ${tableName} where errorMsg is not null")
    int checkError(@Param("tableName") String tableName);

    @Select("select * from ${tableName}")
    List<Map<String,Object>> getErrorMsg(@Param("tableName") String tableName);

    @Select("select count(1) from ${tableName}")
    Integer getCount(@Param("tableName") String tableName);

    @Select("select count(1) from ${tableName} where errorMsg is not null")
    Integer getErrorCount(@Param("tableName") String tableName);

    @Update("${sql}")
    Integer update(@Param("sql") String sql);

    @Update("${sql}")
    Integer delete(@Param("sql") String sql);

    @Update("${sql}")
    Integer insert(@Param("sql") String sql);

}
